// pages/mypost/mypost.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    posts:[],
    image:wx.getStorageSync('users').user_image_src
  },

  finished:function(e){
    var method=e;
    wx.showModal({
      title:'温馨提示',
      content:'您已完成该帖子',
      confirmText:'确认',
      cancelText:'取消',
      success:()=>{
        wx.request({
          url: `https://api.yidan.work:2004/myPost/${method.currentTarget.id}`,
          header:{'content-type':'application/JSON'},
          method: 'DELETE',
          success:()=>{
            console.log('删除成功');
            getCurrentPages()[getCurrentPages().length - 1].onLoad()
          },
          fail:(res)=>{
            console.log(res)
          }
          
        })
      }
    })
  },

  resend:function(){
    wx.showModal({
      title:'温馨提示',
      content:'您确认要重新发帖',
      confirmText:'确认',
      cancelText:'取消',
      success:()=>{
        wx.switchTab({
          url: '/pages/add/add',
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this;
    wx.request({
      url: `https://api.yidan.work:2004/myPost/${wx.getStorageSync('user_id')}`,
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      method: 'GET',
      success:(res)=>{
        console.log(res.data)
        this.setData({
          posts:res.data,
          image:res.data.user_image_src
        })
      },
      fail:(res)=>{
        this.setData({
          posts:[]
        }) 
      }
    })
  },

  onRefresh:function(){
    //导航条加载动画
    wx.showNavigationBarLoading()
    //loading 提示框
    wx.showLoading({
      title: 'Loading...',
    })
    console.log("下拉刷新啦");
    setTimeout(function () {
      wx.hideLoading();
      wx.hideNavigationBarLoading();
      //停止下拉刷新
      wx.stopPullDownRefresh();
    }, 2000)
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh:function(){
    this.onRefresh();
  },
})